package com.linghang.learnspringboot.controller;

import com.linghang.learnspringboot.domain.Test;
import com.linghang.learnspringboot.service.TestService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController//返回字符串
//@Controller//返回页面

/**
 * GET
 * POST
 * PUT
 * DELETE
 *
 * 获取用户：
 * 传统；/user?id=1
 * restful风格：/user/1
 *
 * 如果只是简单地用@RequestMapping注解，表示这个接口支持所有请求方式
 * @GetMapping 只支持GET方法
 * @PutMapping
 * @PostMapping
 * @DeleteMapping
 * @PostMapping(value="/hello",method=RequestMethod.GET)
 */

public class TestController {
    @Value("${test.hello}")
    private  String testHello;

    @Resource
    private TestService testService;

    @GetMapping("/hello")
    public String hello(){
        return "Hello Spring Boot!"+testHello;
    }

//直接写name参数，和http测试参数名字一样，String会自动映射

    @PostMapping("/hello/post")
    public String helloByPost(String name){
        return "Hello Spring Boot!(post)"+name;
    }


    @GetMapping("/test/list")
    public List<Test> list(){
        return testService.list();
    }

}



